"""
API数据模型

定义用于API接口的Pydantic模型
"""

from typing import Optional, List
from pydantic import BaseModel, Field
from datetime import datetime


class UserInfo(BaseModel):
    """用户信息模型"""
    id: int
    username: str
    email: Optional[str] = None
    is_active: bool = True
    can_read: bool = True
    can_write: bool = True
    created_at: Optional[datetime] = None
    updated_at: Optional[datetime] = None


class UserCreate(BaseModel):
    """创建用户模型"""
    username: str = Field(..., min_length=3, max_length=50)
    password: str = Field(..., min_length=6)
    email: Optional[str] = None
    can_read: bool = True
    can_write: bool = True


class UserUpdate(BaseModel):
    """更新用户模型"""
    email: Optional[str] = None
    is_active: Optional[bool] = None
    can_read: Optional[bool] = None
    can_write: Optional[bool] = None


class ServiceStatus(BaseModel):
    """服务状态模型"""
    status: str
    version: str
    uptime: float
    webdav_enabled: bool
    total_users: int
    active_users: int


class FileInfo(BaseModel):
    """文件信息模型"""
    name: str
    path: str
    size: Optional[int] = None
    is_directory: bool
    created_at: Optional[datetime] = None
    modified_at: Optional[datetime] = None


class ApiResponse(BaseModel):
    """API响应模型"""
    success: bool
    message: str
    data: Optional[dict] = None


class ErrorResponse(BaseModel):
    """错误响应模型"""
    success: bool = False
    error: str
    detail: Optional[str] = None